<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>我的商户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../bangnuo/admin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../bangnuo/admin/style/admin.css" media="all">
</head>

<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">编号</label>
                    <div class="layui-input-block">
                        <input type="text" name="merchantsNumber" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">登录名</label>
                    <div class="layui-input-block">
                        <input type="text" name="merchantsUsername" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">真实姓名</label>
                    <div class="layui-input-block">
                        <input type="text" name="merchantsName" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">电话</label>
                    <div class="layui-input-block">
                        <input type="text" name="merchantsPhone" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">邮箱</label>
                    <div class="layui-input-block">
                        <input type="text" name="merchantsEmail" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <!--<div class="layui-inline">
                    <label class="layui-form-label">所属公司</label>
                    <div class="layui-input-block">
                        <select name="merchantsIdAgentId" id="merchantsIdAgentId">
                        </select>
                    </div>
                </div>-->

                <div class="layui-inline">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <select name="merchantsState">
                            <option value="">全部</option>
                            <option value="1">正常</option>
                            <option value="0">锁定</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <table id="merchants-demo" lay-filter="merchants-demo"></table>
            <script type="text/html" id="imgTpl">
                <img style="display: inline-block; width: 50%; height: 100%;" src={ { d.avatar }}>
            </script>
            <script type="text/html" id="table-useradmin-webuser">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="qualification"><i
                        class="layui-icon layui-icon-picture"></i>通道申请</a>
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i
                        class="layui-icon layui-icon-edit"></i>编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i
                        class="layui-icon layui-icon-delete"></i>删除</a>
            </script>
        </div>
    </div>
</div>

</body>
<script src="../../../bangnuo/admin/layui/layui.js"></script>
<script src="../../../bangnuo/admin/js/jquery-1.8.0.min.js"></script>
<!--状态-->
<script type="text/html" id="tpl_merchantsState">
    {{# if(d.status == 1){ }}
    <b style="color: blue;">正常</b>
    {{# } else { }}
    <b style="color: red;">锁定</b> {{# } }}
</script>
<script>
    // 公司
    layui.use(['form', 'upload', 'layer'], function () {

        var form = layui.form;

        var resultData;
        var htmls = '<option value="">请选择</option>'; //全局变量

        //检查项目添加到下拉框中
        $.ajax({
            url: '/agentEntity/agent',
            dataType: 'json',
            type: 'get',
            success: function (data) {
                resultData = data.queryResult.list;
                for (var x in resultData) {
                    htmls += '<option value = "' + resultData[x].id + '">' + resultData[x].company_name + '</option>';
                }
                $("#merchantsIdAgentId").html(htmls);
                form.render('select');
                //重新渲染 固定写法
            }
        })
    });
</script>
<script>
    // 业务员
    layui.use(['form', 'upload', 'layer'], function () {

        var form = layui.form;

        var resultData;
        var htmls = '<option value="">请选择</option>'; //全局变量

        //检查项目添加到下拉框中
        $.ajax({
            url: '',
            dataType: 'json',
            type: 'get',
            success: function (data) {
                resultData = data.data;
                for (var x in resultData) {
                    htmls += '<option value = "' + resultData[x].id + '">' + resultData[x].comp + '</option>';
                }
                $("#merchantsIdAdminId").html(htmls);
                form.render('select');

                //重新渲染 固定写法
            }
        })
    });
</script>
<script>
    layui.use(['util', 'table', 'form'], function () {
        var table = layui.table,
            form = layui.form;
        form.on('submit(LAY-user-front-search)', function (data) {
            var merchantsEntity = {
                //"merchantsNumber": data.field.merchantsNumber,
                "username": data.field.merchantsUsername,
                "name": data.field.merchantsName,
                "phone": data.field.merchantsPhone,
                "email": data.field.merchantsEmail,
                // "merchantsIdAgentId": data.field.merchantsIdAgentId,
                "merchantsIdAdminId": data.field.merchantsIdAdminId,
                "status": data.field.merchantsState
            }
            table.reload('merchants-overloading', {
                url: '/commercial/list',
                where: merchantsEntity,
                page: {
                    curr: 1
                }
            });
            return false;
        });
        //第一个实例
        table.render({
            elem: '#merchants-demo',
            method: "post",
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            contentType: "application/json;charset=UTF-8",
            url: '/commercial/list', //数据接口
            page: true, //开启分页
            parseData: function (res) { //res 即为原始返回的数据
                console.log("res执行", res);
                return {
                    "code": 0, //解析接口状态
                    "msg": "", //解析提示文本
                    "count": res.queryResult.total, //解析数据长度
                    "data": res.queryResult.list//解析数据列表
                };
            },
            limit: 5,
            id: "merchants-overloading",
            limits: [5, 10, 20, 50, 100],
            cols: [
                [ //表头
                    {
                        field: 'id',
                        title: 'ID',
                        width: 80,
                        sort: true,
                        fixed: 'left'
                    }, {
                    field: 'companyName',
                    title: '公司名称',
                    width: 100
                }, {
                    field: 'username',
                    title: '登陆名',
                    width: 80
                }, {
                    field: 'name',
                    title: '姓名',
                    width: 80
                }, {
                    field: 'phone',
                    title: '电话',
                    width: 80
                }, {
                    field: 'email',
                    title: '邮箱',
                    width: 80
                }, {
                    field: '',
                    title: '所属公司',
                    width: 90
                }, {
                    field: '',
                    title: '业务员',
                    width: 80
                }, {
                    field: 'wxStatus',
                    title: '微信通道审核状态',
                    width: 80
                }, {
                    field: 'aliPayStatus',
                    title: '支付宝通道审核状态',
                    width: 80
                }, {
                    field: 'jlStatus',
                    title: '建联通道审核状态',
                    width: 80
                }, {
                    field: 'status',
                    title: '状态',
                    width: 60,
                    templet: "#tpl_merchantsState"
                }, {
                    field: 'createTime',
                    title: '创建时间',
                    width: 160,
                    templet: '<div>{{ layui.util.toDateString(d.createTime, "yyyy-MM-dd HH:mm:ss") }}</div>'
                }, {
                    title: '操作',
                    fixed: 'right',
                    width: 160,
                    align: 'center',
                    toolbar: '#table-useradmin-webuser'
                }
                ]
            ]
        });
        table.on('tool(merchants-demo)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
            if (layEvent === 'del') { //删除
                layer.confirm('真的删除行么', function (index) {
                    obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                    layer.close(index);
                    //向服务端发送删除指令
                    $.ajax({
                        type: "POST",
                        url: "/commercial/delete/" + data.id,
                        async: true,
                        success: function (data) {
                            if (data.success == true) {
                                layer.msg("删除成功");
                            } else {
                                layer.msg("删除失败");
                            }
                        }
                    });
                });
            } else if (layEvent === 'edit') { //编辑
                //do something
                //同步更新缓存对应的值
                layer.open({
                    type: 2,
                    title: '修改商户',
                    area: ['800px', '600px'],
                    content: 'operation/edit-merchants.html?id=' + data.id //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                });
            } else if (layEvent == 'qualification') {
                layer.open({
                    type: 2,
                    title: '商户资质',
                    area: ['800px', '600px'],
                    content: 'operation/qualification.html0?id=' + data.id //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                });
            }
        });
    });
</script>

</html>